// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   SourceFile

package com.sgame.android.network;

import android.content.Context;
import java.io.*;

// Referenced classes of package com.mobage.global.android.b:
//            f

public final class CacheDisk
{

    public static void Save(Context context, String s, Object obj)
        throws IOException
    {
        obj = toBytes(obj);
        FileOutputStream ostream = context.openFileOutput(s, 0);
        ostream.write(((byte []) (obj)));
        ostream.close();
    }

    public static Object Load(Context context, String s)
        throws IOException
    {
    	FileInputStream istream = context.openFileInput(s);
    	byte [] buffer;
        for(buffer = new byte[istream.available()]; istream.read(buffer) != -1;);
        istream.close();
        return toObject(buffer);
    }

    private static byte[] toBytes(Object obj)
    {
        byte abyte0[];
        ByteArrayOutputStream bytearrayoutputstream;
        abyte0 = null;
        try
        {
	        bytearrayoutputstream = new ByteArrayOutputStream();
	        ObjectOutputStream objectoutputstream;
	        (objectoutputstream = new ObjectOutputStream(bytearrayoutputstream)).writeObject(obj);
	        objectoutputstream.flush();
	        objectoutputstream.close();
	        bytearrayoutputstream.close();
	        abyte0 = bytearrayoutputstream.toByteArray();
        }
        catch(IOException ex)
        {
        	return null;
        }
        return abyte0;
    }

    private static Object toObject(byte abyte0[])
    {
        Object obj = null;
        ObjectInputStream bStream;
		try {
			bStream = new ObjectInputStream(new ByteArrayInputStream(abyte0));
			obj = bStream.readObject();
		} catch (StreamCorruptedException e) {
		} catch (IOException e) {
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
        return obj;
    }
}
